﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.Text;

public partial class editmanage : System.Web.UI.Page
{
	public string sss = "";
	protected void Page_Load(object sender,EventArgs e)
	{if (Session["User"]==null)
		{
			Response.Write("<script language=javascript>alert('您没有管理权限或者还没有登录，请先登录！');window.open('../login.aspx','_top');</script>");
			Response.End();
		}
		if (!Page.IsPostBack)
        {
            string id = Request.QueryString["userid"];
            HiddenID.Value = id;
            if (!string.IsNullOrEmpty(id))
            {
                DataSet dsc = Socut.Data.ExecuteDataSet("select LoginName,isadmin,limitcheck,truename,depart from web_admin where id=" + id);
                LoginName.Text = dsc.Tables[0].Rows[0][0].ToString();
				truename.Text = dsc.Tables[0].Rows[0][3].ToString();
				depart.Text = dsc.Tables[0].Rows[0][4].ToString();
				string isadmin = dsc.Tables[0].Rows[0][1].ToString();
				string[] strqx = dsc.Tables[0].Rows[0][2].ToString().Split(',');
				//Response.Write(strqx);
				//Response.End();
				
				DataSet dst = Socut.Data.ExecuteDataSet("select * from web_notice_bigclass order by bigclassorder");
				//string str = dst.Tables[0].Rows[0]["ks"].ToString();;
				//string[] strtype=str.Split(',');
				//dst.Clear();
				//sdatype.Dispose();
		
				//Response.Write(strtype);
		
				DataSet ds = Socut.Data.ExecuteDataSet("select * from web_notice_smallclass order by smallclassorder");
		
				string strbigclass = "";
				string strsmallclass = "";
				
				System.Text.StringBuilder sb = new System.Text.StringBuilder();
								sb.Append("<table width='100%' border='0' align='center' cellpadding='0' cellspacing='1' bgcolor='#D7EBEC' class='dhlink'><tr><td colspan='6' height='30' bgcolor='#F4FCFF'><font color='#00527A'><b>文章系统管理权限</b></font></td></tr><tr>");
				sb.Append("<td width=100% height=20 bgcolor='#ffffff'>");
							if (check_class(strqx, "001"))
							{
								sb.Append("<input id='LimitCheck' name='LimitCheck' type='checkbox' style='border:0 ' value='001' checked='true' />添加文章");
							}
							else
							{
								sb.Append("<input id='LimitCheck' name='LimitCheck' type='checkbox' style='border:0 ' value='001' />添加文章");
							}
							if (check_class(strqx, "002"))
							{
								sb.Append("<input id='LimitCheck' name='LimitCheck' type='checkbox' style='border:0 ' value='002' checked='true' />管理文章");
							}
							else
							{
								sb.Append("<input id='LimitCheck' name='LimitCheck' type='checkbox' style='border:0 ' value='002' />管理文章");
							}
							if (check_class(strqx, "000"))
							{
								sb.Append("<input id='LimitCheck' name='LimitCheck' type='checkbox' style='border:0 ' value='000' checked='true' />管理微博");
							}
							else
							{
								sb.Append("<input id='LimitCheck' name='LimitCheck' type='checkbox' style='border:0 ' value='000' />管理微博");
							}
							if (check_class(strqx, "003"))
							{
								sb.Append("<input id='LimitCheck' name='LimitCheck' type='checkbox' style='border:0 ' value='003' checked='true' />管理小类");
							}
							else
							{
								sb.Append("<input id='LimitCheck' name='LimitCheck' type='checkbox' style='border:0 ' value='003' />管理小类");
							}
							if (check_class(strqx, "004"))
							{
								sb.Append("<input id='LimitCheck' name='LimitCheck' type='checkbox' style='border:0 ' value='004' checked='true' />管理大类");
							}
							else
							{
								sb.Append("<input id='LimitCheck' name='LimitCheck' type='checkbox' style='border:0 ' value='004' />管理大类");
							}
				sb.Append("</td></tr>");
				sb.Append("</table>");
				
				sb.Append("<table width='100%' border='0' align='center' cellpadding='0' cellspacing='1' bgcolor='#D7EBEC' class='dhlink'><tr><td colspan='6' height='30' bgcolor='#F4FCFF'><font color='#00527A'><b>音乐系统管理权限</b></font></td></tr><tr>");
				sb.Append("<td width=100% height=20 bgcolor='#ffffff'>");
							if (check_class(strqx, "021"))
							{
								sb.Append("<input id='LimitCheck' name='LimitCheck' type='checkbox' style='border:0 ' value='021' checked='true' />添加音乐");
							}
							else
							{
								sb.Append("<input id='LimitCheck' name='LimitCheck' type='checkbox' style='border:0 ' value='021' />添加音乐");
							}
							if (check_class(strqx, "022"))
							{
								sb.Append("<input id='LimitCheck' name='LimitCheck' type='checkbox' style='border:0 ' value='022' checked='true' />管理音乐");
							}
							else
							{
								sb.Append("<input id='LimitCheck' name='LimitCheck' type='checkbox' style='border:0 ' value='022' />管理音乐");
							}
							if (check_class(strqx, "023"))
							{
								sb.Append("<input id='LimitCheck' name='LimitCheck' type='checkbox' style='border:0 ' value='023' checked='true' />管理音乐小类");
							}
							else
							{
								sb.Append("<input id='LimitCheck' name='LimitCheck' type='checkbox' style='border:0 ' value='023' />管理音乐小类");
							}
							/*if (check_class(strqx, "024"))
							{
								sb.Append("<input id='LimitCheck' name='LimitCheck' type='checkbox' style='border:0 ' value='024' checked='true' />管理音乐大类");
							}
							else
							{
								sb.Append("<input id='LimitCheck' name='LimitCheck' type='checkbox' style='border:0 ' value='024' />管理音乐大类");
							}*/
				sb.Append("</td></tr>");
				sb.Append("</table>");
				
				sb.Append("<table width='100%' border='0' align='center' cellpadding='0' cellspacing='1' bgcolor='#D7EBEC' class='dhlink'><tr><td colspan='6' height='30' bgcolor='#F4FCFF'><font color='#00527A'><b>案件管理</b></font></td></tr><tr>");
				sb.Append("<td width=100% height=20 bgcolor='#ffffff'>");
							if (check_class(strqx, "006"))
							{
								sb.Append("<input id='LimitCheck' name='LimitCheck' type='checkbox' style='border:0 ' value='006' checked='true' />办案情况管理");
							}
							else
							{
								sb.Append("<input id='LimitCheck' name='LimitCheck' type='checkbox' style='border:0 ' value='006' />办案情况管理");
							}
							if (check_class(strqx, "007"))
							{
								sb.Append("<input id='LimitCheck' name='LimitCheck' type='checkbox' style='border:0 ' value='007' checked='true' />添加办案情况");
							}
							else
							{
								sb.Append("<input id='LimitCheck' name='LimitCheck' type='checkbox' style='border:0 ' value='007' />添加办案情况");
							}
							if (check_class(strqx, "015"))
							{
								sb.Append("<input id='LimitCheck' name='LimitCheck' type='checkbox' style='border:0 ' value='015' checked='true' />法官管理");
							}
							else
							{
								sb.Append("<input id='LimitCheck' name='LimitCheck' type='checkbox' style='border:0 ' value='015' />法官管理");
							}
							if (check_class(strqx, "016"))
							{
								sb.Append("<input id='LimitCheck' name='LimitCheck' type='checkbox' style='border:0 ' value='016' checked='true' />添加法官");
							}
							else
							{
								sb.Append("<input id='LimitCheck' name='LimitCheck' type='checkbox' style='border:0 ' value='016' />添加法官");
							}
							if (check_class(strqx, "017"))
							{
								sb.Append("<input id='LimitCheck' name='LimitCheck' type='checkbox' style='border:0 ' value='017' checked='true' />excel数据导入");
							}
							else
							{
								sb.Append("<input id='LimitCheck' name='LimitCheck' type='checkbox' style='border:0 ' value='017' />excel数据导入");
							}
							
							if (check_class(strqx, "0072"))
							{
								sb.Append("<input id='LimitCheck' name='LimitCheck' type='checkbox' style='border:0 ' value='0072' checked='true' />修改柱状图");
							}
							else
							{
								sb.Append("<input id='LimitCheck' name='LimitCheck' type='checkbox' style='border:0 ' value='0072' />修改柱状图");
							}

				sb.Append("</td></tr>");
				sb.Append("</table>");
				
				sb.Append("<table width='100%' border='0' align='center' cellpadding='0' cellspacing='1' bgcolor='#D7EBEC' class='dhlink'><tr><td colspan='6' height='30' bgcolor='#F4FCFF'><font color='#00527A'><b>预约留言管理</b></font></td></tr><tr>");
				sb.Append("<td width=100% height=20 bgcolor='#ffffff'>");
							if (check_class(strqx, "005"))
							{
								sb.Append("<input id='LimitCheck' name='LimitCheck' type='checkbox' style='border:0 ' value='005' checked='true' />管理预约");
							}
							else
							{
								sb.Append("<input id='LimitCheck' name='LimitCheck' type='checkbox' style='border:0 ' value='005' />管理预约");
							}
							if (check_class(strqx, "0052"))
							{
								sb.Append("<input id='LimitCheck' name='LimitCheck' type='checkbox' style='border:0 ' value='0052' checked='true' />管理留言");
							}
							else
							{
								sb.Append("<input id='LimitCheck' name='LimitCheck' type='checkbox' style='border:0 ' value='0052' />管理留言");
							}
							if (check_class(strqx, "0053"))
							{
								sb.Append("<input id='LimitCheck' name='LimitCheck' type='checkbox' style='border:0 ' value='0053' checked='true' />在线咨询");
							}
							else
							{
								sb.Append("<input id='LimitCheck' name='LimitCheck' type='checkbox' style='border:0 ' value='0053' />在线咨询");
							}

				sb.Append("</td></tr>");
				sb.Append("</table>");
				
				
				sb.Append("<table width='100%' border='0' align='center' cellpadding='0' cellspacing='1' bgcolor='#D7EBEC' class='dhlink'><tr><td colspan='6' height='30' bgcolor='#F4FCFF'><font color='#00527A'><b>友情链接管理权限</b></font></td></tr><tr>");
				sb.Append("<td width=100% height=20 bgcolor='#ffffff'>");
							if (check_class(strqx, "011"))
							{
								sb.Append("<input id='LimitCheck' name='LimitCheck' type='checkbox' style='border:0 ' value='011' checked='true' />管理连接");
							}
							else
							{
								sb.Append("<input id='LimitCheck' name='LimitCheck' type='checkbox' style='border:0 ' value='011' />管理连接");
							}
							if (check_class(strqx, "012"))
							{
								sb.Append("<input id='LimitCheck' name='LimitCheck' type='checkbox' style='border:0 ' value='012' checked='true' />添加链接");
							}
							else
							{
								sb.Append("<input id='LimitCheck' name='LimitCheck' type='checkbox' style='border:0 ' value='012' />添加链接");
							}
				sb.Append("</td></tr>");
				sb.Append("</table>");
				
				sb.Append("<table width='100%' border='0' align='center' cellpadding='0' cellspacing='1' bgcolor='#D7EBEC' class='dhlink'><tr><td colspan='6' height='30' bgcolor='#F4FCFF'><font color='#00527A'><b>在线调查管理权限</b></font></td></tr><tr>");
				sb.Append("<td width=100% height=20 bgcolor='#ffffff'>");
							if (check_class(strqx, "018"))
							{
								sb.Append("<input id='LimitCheck' name='LimitCheck' type='checkbox' style='border:0 ' value='018' checked='true' />管理在线调查");
							}
							else
							{
								sb.Append("<input id='LimitCheck' name='LimitCheck' type='checkbox' style='border:0 ' value='018' />管理在线调查");
							}
							if (check_class(strqx, "019"))
							{
								sb.Append("<input id='LimitCheck' name='LimitCheck' type='checkbox' style='border:0 ' value='019' checked='true' />添加在线调查");
							}
							else
							{
								sb.Append("<input id='LimitCheck' name='LimitCheck' type='checkbox' style='border:0 ' value='019' />添加调查链接");
							}
				sb.Append("</td></tr>");
				sb.Append("</table>");
				
								sb.Append("<table width='100%' border='0' align='center' cellpadding='0' cellspacing='1' bgcolor='#D7EBEC' class='dhlink'><tr><td colspan='6' height='30' bgcolor='#F4FCFF'><font color='#00527A'><b>管理员管理权限</b></font></td></tr><tr>");
				sb.Append("<td width=100% height=20 bgcolor='#ffffff'>");
							if (check_class(strqx, "013"))
							{
								sb.Append("<input id='LimitCheck' name='LimitCheck' type='checkbox' style='border:0 ' value='013' checked='true' />添加管理员");
							}
							else
							{
								sb.Append("<input id='LimitCheck' name='LimitCheck' type='checkbox' style='border:0 ' value='013' />添加管理员");
							}
							if (check_class(strqx, "014"))
							{
								sb.Append("<input id='LimitCheck' name='LimitCheck' type='checkbox' style='border:0 ' value='014' checked='true' />管理员管理");
							}
							else
							{
								sb.Append("<input id='LimitCheck' name='LimitCheck' type='checkbox' style='border:0 ' value='014' />管理员管理");
							}
				sb.Append("</td></tr>");
				sb.Append("</table>");
		
				foreach (DataRow dr1 in dst.Tables[0].Rows)
				{
					int count = 0;
					strbigclass = dr1["id"].ToString();
					sb.Append("<table width='100%' border='0' align='center' cellpadding='0' cellspacing='1' bgcolor='#D7EBEC' class='dhlink'><tr><td colspan='6' height='30' bgcolor='#F4FCFF'><font color='#00527A'><b>" + dr1["bigclassname"] + "</b></font></td></tr><tr>");
					foreach (DataRow dr2 in ds.Tables[0].Rows)
					{
						strsmallclass = dr2["bigclassid"].ToString();
						if (check_class(strbigclass.Split(','), strsmallclass))
						{
							count++;
							string strsid=dr2["id"].ToString();
							sb.Append("<td width=15% height=20 bgcolor='#ffffff'>");
							if (check_class(strqx, strsid))
							{
								sb.Append("<input id='LimitCheck' name='LimitCheck' type='checkbox' style='border:0 ' value='"+dr2["id"]+"' checked='true' />");

							}
							else
							{
								sb.Append("<input id='LimitCheck' name='LimitCheck' type='checkbox' style='border:0 ' value='"+dr2["id"]+"' />");
							}
							sb.Append("" + dr2["smallclassname"] + "</td>");
							/*
							Zyglqx = Zyglqx + "<input type='checkbox' name='" + _name + "' value='" + i + "' ";
							if (checkqx(strqx, i))
							{
								Zyglqx = Zyglqx + " checked=true ";
							}
							Zyglqx = Zyglqx + ">" + strqxarry[i, 1];
							*/
									
							
							if (count % 6 == 0)
							{
		
								sb.Append("</tr><tr>");
		
		
							}
						}
					}
					int aa = count % 6;
					for (int i = aa; i < 6; i++)
					{
						sb.Append("<td width=15% height=20 bgcolor='#ffffff'>&nbsp;</td>");
					}
					if (sb.ToString().EndsWith("<tr>"))
					{
						sb.Remove(sb.Length - 4, 4);
		
					}
					if (sb.ToString().EndsWith("</td>"))
					{
						sb.Append("</tr>");
					}
					sb.Append("</table>");
				}
				sss = sb.ToString();
				
				
            }
			else
			{
    			Response.Write("<script>alert('操作错误');history.back();</script>");
				
            }
			
        }
	}


	protected void UpdateBtn_Click(object sender,EventArgs e)
	{
		string Msg, Url;
        if (string.IsNullOrEmpty(HiddenID.Value))
        {
            Msg = "操作失败！";
            Url = "manage.aspx";
        }
        else
        {
			string Npwd=FormsAuthentication.HashPasswordForStoringInConfigFile(this.NewPassword.Text, "md5");
			string diction = Request.Form["LimitCheck"];
			//try
//			{
				if (string.IsNullOrEmpty(this.NewPassword.Text))
				{
					Socut.Data.ExecuteNonQuery("update web_admin set LoginName='" + LoginName.Text + "',limitcheck='"+diction+"',truename='"+truename.Text+"',depart='"+depart.Text+"' where id=" + HiddenID.Value);
					//Response.Write(LoginName.Text);
					//Response.End();
					Msg = "用户信息修改成功！";
					Url = "manage.aspx";
					CommonFunction.ShowMessage(Msg,Url);
				}
				else
				{
					
					Socut.Reader drp = new Socut.Reader("select * from web_admin where id=" + HiddenID.Value);
					drp.Read();			
	
	
					Socut.Data.ExecuteNonQuery("update web_admin set LoginName='" + LoginName.Text + "',Pwd='" + Npwd + "',limitcheck='"+diction+"',truename='"+truename.Text+"',depart='"+depart.Text+"' where id=" + HiddenID.Value);
					Msg = "用户密码信息修改成功！";
					Url = "manage.aspx";
					CommonFunction.ShowMessage(Msg,Url);
	
				}
			//}
//			catch
//			{
//					Msg = "操作错误！";
//					Url = "manage.aspx";
//					CommonFunction.ShowMessage(Msg,Url);
//	
//			}
        }
        
	}

	protected void ReturnBtn_Click(object sender,EventArgs e)
	{
		Response.Redirect("Manage.aspx");
	}
	
		private bool check_class(string[] ksarry, string ksid)
    {
        for (int i = 0; i < ksarry.Length; i++)
        {
            if (ksarry[i] == ksid)
            {
                return true;
            }
        }
        return false;
    }

}
